<?php

use yii\db\Migration;

/**
 * Class m211202_140919_create_rbac_audio_service
 */
class m211202_140919_create_rbac_audio_service extends Migration
{
        /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $auth = Yii::$app->authManager;

        $permissionCreate = $auth->createPermission('createAudioService');
        $auth->add($permissionCreate);

        $permissionUpdate = $auth->createPermission('updateAudioService');
        $auth->add($permissionUpdate);

        $permissionDelete = $auth->createPermission('deleteAudioService');
        $auth->add($permissionDelete);

        $permissionBrowse = $auth->createPermission('browseAudioService');
        $auth->add($permissionBrowse);

        $userRole = $auth->createRole('audioServiceUser');
        $auth->add($userRole);

        $managerRole = $auth->createRole('audioServiceManager');
        $auth->add($managerRole);

        $auth->addChild($userRole, $permissionBrowse);

        $auth->addChild($managerRole, $permissionCreate);
        $auth->addChild($managerRole, $permissionUpdate);
        $auth->addChild($managerRole, $permissionDelete);
        $auth->addChild($managerRole, $permissionBrowse);
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        $auth = Yii::$app->authManager;

        $auth->remove($auth->getPermission('createAudioService'));
        $auth->remove($auth->getPermission('updateAudioService'));
        $auth->remove($auth->getPermission('deleteAudioService'));
        $auth->remove($auth->getPermission('browseAudioService'));
        $auth->remove($auth->getRole('audioServiceUser'));
        $auth->remove($auth->getRole('audioServiceManager'));
    }
}
